#include <stdio.h>
#include "nuclei_sdk_hal.h"
#include "nuclei_libopt.h"

#define ARR_SIZE 10
uint16_t uart0_send_buffer[ARR_SIZE]={ 0x101 ,0x102,0x103,0x104,0x105,0x106,0x107,0x108,0x109,0x10a};
uint16_t uart0_send_buffer1[ARR_SIZE]={ 0x31 ,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a};
uint16_t uart0_receive_buffer[ARR_SIZE]={0};
uint16_t uart0_receive_buffer1[ARR_SIZE]={0};
uint8_t err_count=0;
uint8_t state=0;

ErrStatus memory_compare(uint16_t* src, uint16_t* dst, uint16_t length) 
{
    while(length--){
        if(*src++ != *dst++)
            return ERROR;
    }
    return SUCCESS;
}



void main(void )
{

    uart_init(UART0, 115200,UART_BIT_LENGTH_9);

    int i=0,j=0,state0=0,state1=0;
    uart_clean_fifo(UART0);
    do{
        uart_write_9bit(UART0,uart0_send_buffer[i]);
        uart0_receive_buffer[i]=uart_read_9bit(UART0);
    }while((++i)<ARR_SIZE);
    
    uart_init(UART0, 115200,UART_BIT_LENGTH_6);
    uart_clean_fifo(UART0);
    do{
        uart_write(UART0,uart0_send_buffer1[j]);
        uart0_receive_buffer1[j]=uart_read(UART0);
    }while((++j)<ARR_SIZE);

    state0=memory_compare(uart0_send_buffer,uart0_receive_buffer,ARR_SIZE);
    state1=memory_compare(uart0_send_buffer1,uart0_receive_buffer1,ARR_SIZE);

    #ifdef CFG_SIMULATION
        pass_fail_simulation(state0&state1);
    #endif 

// gpio init
	gd_eval_led_init(LED2);	// sf1 mini LED_D5

	if(state0&state1)
	{
		// choose right func to drive LED.
//         gd_eval_led_on(LED2);	// drive LED '+';
		 gd_eval_led_off(LED2);		// drive LED '-';
	}
    else
    {
        while(1)
        {
            gd_eval_led_toggle(LED2);
            delay_1ms(500);
        }
    }
    while(1);
    return;
}
